<?php
/**
 * Class Lib_Request_Aes
 */

class Lib_Request_Aes
{
    private $key = null;
    public function __construct($key)
    {
        $this->key = $key;
    }

    /**
     * aes-128-cbc加密
     *
     * @param string $data 需要加密的数据
     * @return 加密后的数据
     */
    public function encrypt($data) {

        $encryptedData = openssl_encrypt($data, 'AES-256-ECB', $this->key, OPENSSL_RAW_DATA);

        return base64_encode($encryptedData);
    }

    /**
     * aes-128-cbc解密
     *
     * @param string $data 需要解密的数据
     * @return 解密后的数据
     */
    public function decrypt($data) {
        $base64de_encryptedData = base64_decode($data);
        return  openssl_decrypt($base64de_encryptedData, 'AES-256-ECB', $this->key, OPENSSL_RAW_DATA);;
    }

}
